// const p = new Promise((resolve, reject) => {
//   // pedding => filfilled
//   // resolve()
//   // pedding => rejected
//   reject()
// })

// // pedding => filfilled
// p.then(() => { console.log('then') })
// // pedding => rejected
// p.catch(() => {console.log('catch')})
// // pedding => rejected | filfilled
// p.finally(() => {console.log('finally')}) 


// const P1 = Promise.resolve(1)
// const P2 = Promise.reject(2)
// console.log(P1, P2)


const p1 = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve('p1 data')
  }, Math.random() * 1000)
})


const p2 = new Promise((resolve, reject) => {
  setTimeout(() => {
    reject('p2 data')
  }, Math.random() * 1000)
})


const p3 = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve('p3 data')
  }, Math.random() * 1000)
})

Promise.all([p1, p2, p3]).then((result) => {
  console.log('成功了！！', result)
}).catch((error) => {
  console.log('失败了', error)
})



Promise.race([p1, p2, p3]).then((result) => {
  console.log('成功',result)
}).catch((error) => {
  console.log('失败', error)
})